<template>
  <div class="icons">
    <swiper :options="swiperOption">
    <swiper-slide v-for="(page,index) of pages" :key="index">
      <div class="icon" v-for=" item of page" :key="item.id">
        <div class="icon-img">
          <img class="icon-img-content" :src="item.imgUrl">
        </div>
        <h1 class="icon-desc">{{item.desc}}</h1>
      </div>
    </swiper-slide>
    </swiper>
  </div>
  
</template>

<script>
export default {
  name: "Icons",
  props:{
    iconsList:Array
  },
  data() {
    return {
      // 阻止导航条自动轮播
      swiperOption: {
        autoplay: false
      },
    };
  },
  computed: {
    pages() {
      // 空数组
      const pages = [];
      // 遍历传入进来的数组
      this.iconsList.forEach((item, index) => {
        // 除8 取余 0 1
        const page = Math.floor(index / 8);
        // 取反判断 page只为 0 1
        if (!pages[page]) {
          // 取反为true进判断
          // 空数组内创建一个数组
          pages[page] = [];
        }
        // 将遍历的元素添加进数组
        pages[page].push(item);
      });
      return pages;
    }
  }
};
</script>

<style lang='less' scoped>
@import "~@/assets/styles/varibles.less";
.icons {
  // // background-color: #bfa;
  height: 0;
  padding-bottom: 50%;
  overflow: hidden;
  margin-top:.1rem; 
  .icon {
    position: relative;
    float: left;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    // background-color: red;
    .icon-img {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0.44rem;
      // background-color: blue;
      box-sizing: border-box;
      padding: 0.1rem;
      .icon-img-content {
        height: 100%;
        display: block;
        margin: 0 auto;
      }
    }
    .icon-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      color: @TextBacc;
      text-align: center;
      .ellipsis();
    }
  }
}
</style>
